import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  define: {
    global: 'window'
  },
  server: {
    host: '0.0.0.0', // <<<< MODIFIED: Makes Vite accessible on your LAN IP
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://localhost:8080', // Backend is on the same machine
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api')
      },
      '/ws-chat': {
        target: 'http://localhost:8080', // WebSocket backend is on the same machine
        ws: true
      },
      // If you need to proxy avatar requests directly through Vite (e.g. if they are part of /api structure)
      // However, current avatar URLs are constructed with full backend address, so direct proxy for them here isn't strictly needed
      // unless you change avatar URL structure to be relative to frontend's origin.
      // For instance, if you make avatar URLs like `/api/avatars/...`
      // '/avatars': { // Example if avatars were served from backend at /avatars and you want to proxy
      //   target: 'http://localhost:8080',
      //   changeOrigin: true,
      // }
    }
  }
})
